home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 1.iso
/
toolbox
/
src
/
exampleCode
/
opengl
/
glx
/
sharelist.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-11
|
7KB
|
276 lines
/*
* Copyright (C) 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
/*
** sharelist.c
**
** Test sharing display list spaces between two contexts. The lists contain
** both geometry and textures.
**
** Simon Hui
** $Revision: 1.1 $
** $Date: 1995/01/27 18:06:01 $
*/
#include <GL/glx.h>
#include <GL/glu.h>
#include <X11/keysym.h>
#include <X11/extensions/sgiXnmbx.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <bstring.h>
#include <math.h>
#include "util.h"
Display *dpy;
XVisualInfo *theVi;
Colormap cmapA, cmapB;
Window winA, winB;
GLXContext cxA, cxB;
GLuint cubeList, checkerList, stripeList;
#define W 200
#define H 200
int width=W, height=H;
int frames=300;
#define TITLE "Shared List Test"
static int attributes[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DEPTH_SIZE, 1,
None,
};
#define Red 0xff, 0, 0
#define Blue 0, 0, 0xff
#define Yellow 0xff, 0xff, 0
static GLubyte checkerTexture[] = {
Blue, Yellow, Blue, Yellow,
Yellow, Blue, Yellow, Blue,
Blue, Yellow, Blue, Yellow,
Yellow, Blue, Yellow, Blue,
};
static GLubyte stripeTexture[] = {
Red, Red, Red, Red,
Red, Yellow, Yellow, Red,
Red, Yellow, Yellow, Red,
Red, Red, Red, Red,
};
GLfloat pts[][3] = {
{ 1, 1, 1 },
{ 1, 1, -1 },
{ 1, -1, -1 },
{ 1, -1, 1 },
{ -1, 1, 1 },
{ -1, 1, -1 },
{ -1, -1, -1 },
{ -1, -1, 1 },
};
int pi[][4] = {
{ 0, 3, 2, 1 },
{ 4, 5, 6, 7 },
{ 4, 7, 3, 0 },
{ 1, 2, 6, 5 },
{ 5, 4, 0, 1 },
{ 2, 3, 7, 6 },
};
float nv[][3] = {
{ 1, 0, 0 },
{ -1, 0, 0 },
{ 0, 0, 1 },
{ 0, 0, -1 },
{ 0, 1, 0 },
{ 0, -1, 0 },
};
void MakeCube(GLuint list)
{
int i;
glNewList(list, GL_COMPILE);
for (i=0; i < 6; i++) {
glNormal3fv(nv[i]);
glBegin(GL_QUADS);
glTexCoord2f(1.0, 1.0);
glVertex3fv(pts[pi[i][0]]);
glTexCoord2f(1.0, 0.0);
glVertex3fv(pts[pi[i][1]]);
glTexCoord2f(0.0, 0.0);
glVertex3fv(pts[pi[i][2]]);
glTexCoord2f(0.0, 1.0);
glVertex3fv(pts[pi[i][3]]);
glEnd();
}
glEndList();
}
void InitContext(void)
{
static float ambient[] = {0.1, 0.1, 0.1, 1.0};
static float diffuse[] = {0.8, 0.8, 0.8, 0.5};
static float position[] = {0.3, 0.3, 1.0, 0.0};
static float front_mat_diffuse[] = {0.8, 0.8, 0.8, 1.0};
static float lmodel_ambient[] = {0.4, 0.0, 0.4, 1.0};
glClearColor(0.0, 0.0, 0.0, 0.0);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glPixelStoref(GL_UNPACK_ALIGNMENT, 1);
glPixelStoref(GL_PACK_ALIGNMENT, 1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_TEXTURE_2D);
glDisable(GL_DITHER);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glShadeModel(GL_FLAT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.0, 1.0, 0.5, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, width, height);
}
void Init( int argc, char **argv, char *geometry )
{
XVisualInfo *vi;
int size;
winA = utilCreateWindow( width, height, 100, 100, None, attributes, "Black",
argc, argv, geometry, &dpy, &vi, NULL, NULL );
winB = utilCreateWindow( width, height, 400, 100, None, attributes, "Black",
argc, argv, geometry, &dpy, &vi, NULL, NULL );
cxA = glXCreateContext(dpy, vi, NULL, GL_TRUE);
cxB = glXCreateContext(dpy, vi, cxA, GL_TRUE);
if (!cxA || !cxB) {
fprintf(stderr, "Cannot create contexts\n");
exit(1);
}
glXMakeCurrent(dpy, winA, cxA);
InitContext();
/* Make three lists: the cube, the checker texture, and the stripe texture*/
cubeList = glGenLists(1);
checkerList = glGenLists(1);
stripeList = glGenLists(1);
MakeCube(cubeList);
glNewList(checkerList, GL_COMPILE);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE,
checkerTexture);
glEndList();
glNewList(stripeList, GL_COMPILE);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE,
stripeTexture);
glEndList();
glXMakeCurrent(dpy, winB, cxB);
InitContext();
size = width * height * 3;
}
static float rotAngle;
void Draw(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(3, 3, 3, 0, 0, 0, 0, 1, 0);
glRotatef(rotAngle, -1.0, 1.0, -1.0);
glCallList(cubeList);
glFinish();
}
void DoTest(void)
{
int size = width * height * 3;
unsigned int chksum, test;
GLuint dlist;
int i;
for (i=0; i < frames; i++) {
rotAngle = i/(frames-1.0) * 360.0;
/* alternate between the checker texture and the stripe texture */
dlist = (i % 2) ? checkerList : stripeList;
glXMakeCurrent(dpy, winA, cxA);
glCallList(dlist);
Draw();
glXMakeCurrent(dpy, winB, cxB);
glCallList(dlist);
Draw();
}
}
void usage(void)
{
fprintf( stderr, "usage: sharelist [-geometry] [frames]\n");
exit(1);
}
int main(int argc, char **argv)
{
XEvent event;
GLboolean needDisplay;
char *geometry=0;
int i;
for (i=1; i<argc; i++) {
if (!strcmp(argv[i], "-geometry")) {
geometry = argv[i];
if (i <= argc-2) {
geometry = argv[i+1];
} else {
usage();
}
}
}
Init( argc, argv, geometry );
glXMakeCurrent( dpy, winA, cxA );
DoTest();
glXMakeCurrent( dpy, None, NULL );
glXDestroyContext( dpy, cxA );
glXDestroyContext( dpy, cxB );
XCloseDisplay(dpy);
}